<template>
  <div>
    <el-select v-model="factoryId" clearable placeholder="请选择工厂" :multiple="multiple" @change="$forceUpdate()" filterable>
      <el-option v-for="factory in factoryOptions"
                 :key="factory.id" :label="factory.name" :value="factory.id"/>
    </el-select>
  </div>
</template>

<script>
import { getFactorySimple } from "@/api/base/factory"
export default {
  name: "SelectFactory",
  props: {
    value: {
      required: true
    },
    multiple: {
      required: false,
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      factoryOptions: [],
      factoryId: this.value,
    }
  },
  watch: {
    value(newVal) {
      this.factoryId = newVal;
    },
    factoryId(newVal, oldVal){
      this.$emit("input", this.factoryId)
    }
  },
  created() {
    this.getFactoryListFun();
  },
  methods: {
    /** 查询工厂列表 */
    getFactoryListFun(){
      getFactorySimple().then(response => {
        this.factoryOptions = response.data;
      })
    },
  }
};
</script>

